<html>
<head><meta charset="utf-8"><title>computed goto · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html">computed goto</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="230150794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/computed%20goto/near/230150794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benedikt Mandelkow <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html#230150794">(Mar 13 2021 at 09:26)</a>:</h4>
<p>after reading <a href="https://github.com/ziglang/zig/issues/8220">https://github.com/ziglang/zig/issues/8220</a> I tried the same in rust  <a href="https://godbolt.org/z/5bxsc8">https://godbolt.org/z/5bxsc8</a> and as far as I can see did not get the desired result, I'm kind of aware that this topic has a long history of discussions, this seems like it would possibly be new though, if rust could be made to generate the same code as zig, which I see no specific reason why it would not be able to</p>
<p>any ideas/ explanations/ examples appreciated :)</p>



<a name="230157694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/computed%20goto/near/230157694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benedikt Mandelkow <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html#230157694">(Mar 13 2021 at 11:51)</a>:</h4>
<p>simplified version <a href="https://godbolt.org/z/o7hjMv">https://godbolt.org/z/o7hjMv</a></p>



<a name="230157849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/computed%20goto/near/230157849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benedikt Mandelkow <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html#230157849">(Mar 13 2021 at 11:54)</a>:</h4>
<p><a href="https://github.com/rust-lang/rfcs/pull/1888#issuecomment-798136497">https://github.com/rust-lang/rfcs/pull/1888#issuecomment-798136497</a> <span aria-label="tada" class="emoji emoji-1f389" role="img" title="tada">:tada:</span></p>



<a name="230159347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/computed%20goto/near/230159347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html#230159347">(Mar 13 2021 at 12:22)</a>:</h4>
<p>Does <a href="https://godbolt.org/z/MnaGz1">https://godbolt.org/z/MnaGz1</a> look more like it?</p>



<a name="230159447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/computed%20goto/near/230159447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html#230159447">(Mar 13 2021 at 12:24)</a>:</h4>
<p>It is somewhat different from the code <code>zig</code> generates, in that the <code>rustc</code> code doesn't go back to the table every time, but in essence its doing a pretty similar thing overall AFAICT.</p>



<a name="230160060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/computed%20goto/near/230160060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benedikt Mandelkow <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html#230160060">(Mar 13 2021 at 12:36)</a>:</h4>
<p>ah of course those assignments have to be unchecked as well, thanks :D <a href="https://godbolt.org/z/d5M1Ma">https://godbolt.org/z/d5M1Ma</a> with fewer flags seems to work as well, I think that may actually be basically the same as zig, yes ...nice :D</p>



<a name="230160184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/computed%20goto/near/230160184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html#230160184">(Mar 13 2021 at 12:38)</a>:</h4>
<p>Ah yeah, I add the flags for myself to declutter the LLVM IR</p>



<a name="230160200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/computed%20goto/near/230160200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html#230160200">(Mar 13 2021 at 12:39)</a>:</h4>
<p>when its all <code>!dbg !123</code> 10 times per line, it becomes quite hard to spot check patterns</p>



<a name="230160541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/computed%20goto/near/230160541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benedikt Mandelkow <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html#230160541">(Mar 13 2021 at 12:45)</a>:</h4>
<p>I'm only slightly suspicious because this seems to work fine even with rustc 1.0 <a href="https://godbolt.org/z/vaWGf3">https://godbolt.org/z/vaWGf3</a> maybe there is something I'm missing as I don't fully understand the different transforms and maybe they are not the same/ that similar after all ...otherwise it seems strange that this did not come up before, or maybe it did and I just did not read it :D i dont know :D</p>



<a name="230161971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/computed%20goto/near/230161971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html#230161971">(Mar 13 2021 at 13:10)</a>:</h4>
<p>People writing rust will not generally reach for <code>get_unchecked_mut</code> for this kind of code, I feel.</p>



<a name="230162385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/computed%20goto/near/230162385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benedikt Mandelkow <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/computed.20goto.html#230162385">(Mar 13 2021 at 13:18)</a>:</h4>
<p>I think there are two distinct things here: assigning the result value and switching on the enum, they should in theory be independent from each other and I may have just mistaken the bounds check of the assignment for a bounds check for the jump target which as I understand is the issue that is solved by computed goto. So I'm not sure if even the first version was totally fine. It would surprise me though if it would be fine because it kind of seems obvious (in hindsight it of course always does)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>